package com.whut.transportation.adapter;

import java.util.List;

import com.whut.transportation.R;
import com.whut.transportation.entity.TrainInfo;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;
/**
 * 列车数据绑定适配器
 * @author yuliyan
 *
 */
public class TrainAdapter extends BaseAdapter {
	
	private List<TrainInfo> trainInfos;//要绑定的数据
	private int resource;//绑定的条目界面
	private LayoutInflater inflater;//布局填充器
	
	public TrainAdapter(Context context,List<TrainInfo> trainInfos, int resource) {
		this.trainInfos = trainInfos;
		this.resource = resource;
		this.inflater = (LayoutInflater)context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
	}
	
	@Override
	public int getCount() {
		return trainInfos.size();
	}

	@Override
	public Object getItem(int arg0) {
		return trainInfos.get(arg0);
	}

	@Override
	public long getItemId(int arg0) {
		return arg0;
	}
 
	@Override
	public View getView(int position, View con, ViewGroup parent) {
		if(con==null){
			con = inflater.inflate(resource, null);
		}
		
		TextView trianId = (TextView) con.findViewById(R.id.trianId);
		TextView trianType = (TextView) con.findViewById(R.id.trianType);
		
		TrainInfo trainInfo = trainInfos.get(position);
		
		trianId.setText(trainInfo.getTrainId().trim());
		trianType.setText(trainInfo.getTrainType().trim());
		
		return con;
	}

}
